#!/usr/bin/perl

use strict;
use warnings;

# 定义站点列表
my @sites = (
    "http://nettest.ulucu.com",
    "http://speed.hfut.edu.cn:80",
    # 添加更多站点
);

# 遍历站点列表
foreach my $site (@sites) {
    my $pid = fork(); # 创建子进程
    if (not defined $pid) {
        print "Failed to fork\n";
        next;
    } elsif ($pid == 0) {
        # 子进程
        my $url;
        my $status_code = system("curl -I -s -o /dev/null -w \"%{http_code}\" \"$site/garbage.php\" > /tmp/status_code.txt");
        open my $fh, '<', "/tmp/status_code.txt" or die $!;
        my $code = <$fh>;
        close $fh;
        
        if ($code == 200) {
            $url = "$site/garbage.php";
        } else {
            $status_code = system("curl -I -s -o /dev/null -w \"%{http_code}\" \"$site/backend/garbage.php\" > /tmp/status_code.txt");
            open my $fh, '<', "/tmp/status_code.txt" or die $!;
            $code = <$fh>;
            close $fh;
            
            if ($code == 200) {
                $url = "$site/backend/garbage.php";
            } else {
                print "Both URLs are not available for site: $site\n";
                exit(0); # 结束子进程
            }
        }
        
        # 生成随机数
        my $random_float = rand();
        
        # 构建下载命令
        my $command = "aria2c -x 16 --human-readable=false --user-agent=\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36\" --dir=/mnt/dltmpfs --out=shadow --allow-overwrite --file-allocation=none \"$url?r=$random_float&ckSize=10000\"";
        
        # 执行下载命令
        system($command);
        
        exit(0); # 结束子进程
    }
    # 父进程会直接跳过这里并继续循环
}

# 等待所有子进程结束
while (wait() != -1) {}

print "All downloads are completed.\n";




#!/usr/bin/perl

use strict;
use warnings;

# 定义站点列表
my @sites = (
    "http://nettest.ulucu.com",
    "http://speed.hfut.edu.cn:80",
    # 添加更多站点
);

# 遍历站点列表
foreach my $site (@sites) {
    my $pid = fork(); # 创建子进程
    if (not defined $pid) {
        print "Failed to fork\n";
        next;
    } elsif ($pid == 0) {
        # 子进程
        my $url;
        my $status_code = `curl -I -s -o /dev/null -w "%{http_code}" "$site/garbage.php"`;
        
        if ($status_code == 200) {
            $url = "$site/garbage.php";
        } else {
            $status_code = `curl -I -s -o /dev/null -w "%{http_code}" "$site/backend/garbage.php"`;
            
            if ($status_code == 200) {
                $url = "$site/backend/garbage.php";
            } else {
                print "Both URLs are not available for site: $site\n";
                exit(0); # 结束子进程
            }
        }
        
        # 生成随机数
        my $random_float = rand();
        
        # 构建下载命令
        my $outfile = "download_$$.log"; # 使用子进程ID作为日志文件名的一部分
        my $command = "aria2c -x 16 --user-agent=\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36\" --dir=/mnt/dltmpfs --out=shadow --allow-overwrite --file-allocation=none \"$url?r=$random_float&ckSize=10000\" > $outfile 2>&1";
        
        # 执行下载命令
        system($command);
        
        exit(0); # 结束子进程
    }
    # 父进程会直接跳过这里并继续循环
}

# 等待所有子进程结束
while (wait() != -1) {}

print "All downloads are completed.\n";
